import 'package:app/http/http.dart';
import 'package:app/model/login_token.dart';
import 'package:dio/dio.dart';
import 'package:retrofit/retrofit.dart';
part 'oauth_token_service.g.dart';

@RestApi()
abstract class OauthTokenService {
  factory OauthTokenService(Dio dio, {String baseUrl}) = _OauthTokenService;
  static OauthTokenService _instance;
  static OauthTokenService getInstance() {
    if (_instance == null) {
      _instance = new OauthTokenService(DioManager.getInstance().dio);
    }
    return _instance;
  }

  /// 用户名+密码登录
  /// @param client_id 应用id
  /// @param client_secret 应用密钥
  /// @param grant_type 授权类型
  /// @param username 用户名
  /// @param password 密码
  @POST("/oauth/token")
  @FormUrlEncoded()
  Future<LoginToken> userLogin(
      @Field() String client_id,
      @Field() String client_secret,
      @Field() String grant_type,
      @Field() String username,
      @Field() String password);

  /// 用户名+密码登录
  /// @param client_id 应用id
  /// @param client_secret 应用密钥
  /// @param grant_type 授权类型
  /// @param mobile_phone 手机号码
  /// @param sms_code 短信验证码
  @POST("/oauth/token")
  @FormUrlEncoded()
  Future<LoginToken> userLoginByMobilePhone(
      @Field() String client_id,
      @Field() String client_secret,
      @Field() String grant_type,
      @Field() String mobile_phone,
      @Field() String sms_code);
}
